import {applyInit} from '@/api/apply.js'
import {setactive}from '@/utils/cookie.js'
const state={
  init:{},
  http:'',
  active:'1',
}
const mutations = {
  SET_INIT:(state,init)=>{
    state.init = init
  },
  SET_HTTP:(state,http)=>{
    state.http = http
  },
  SET_ACTIVE:(state,active)=>{
    state.active = active
    setactive(active)
  },
}
const actions = {
    init({commit}){
      return new Promise((resolve, reject)=>{
        applyInit().then(res=>{
          if(res.code==200){
            if(res.data){
              commit('SET_INIT',res.data)
            }else{
              commit('SET_INIT',{
                aboutus:'',
                alias: "",
                create_time: "",
                db: "",
                delete_time: null,
                district: "",
                domain: "",
                exam_setting: '[]',
                force_bind_wechat: "",
                id: null,
                is_face: '{}',
                label: "",
                logo: "",
                notice: null,
                region_id: null,
                selected_gz: "",
                setting: "{}",
                subdomain: "",
                update_time: "",
                wechat_push_exam_indays: 0,
                wechat_push_interval_days: 0,
                wechat_service: "",
                wxpay: "",
              })
            }
            resolve()
          }else{
            resolve()
          }
        }).catch(()=>{
          reject()
        })
      })
    }
}
export default {
  state,
  mutations,
  actions
}